/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package simhya.model.store.faststore;
import simhya.model.store.Function;
import java.util.ArrayList;
import simhya.matheval.SymbolArray;
import simhya.model.store.Store;


/**
 *
 * @author Luca
 */
public class LinearFunction implements Function{
    private int var;
    private int par;
    private SymbolArray variablesArray;
    private SymbolArray parametersArray;
    private double[] variables;
    private double[] parameters;

    public LinearFunction(Store store, int par, int var) {
        this.variablesArray = (SymbolArray)store.getVariablesReference();
        this.parametersArray = (SymbolArray)store.getParametersReference();
        this.var = var;
        this.par = par;
        store.addExternalFunction(this);
    }

     public void initialize() {
        this.variables = this.variablesArray.getReferenceToValuesArray();
        this.parameters = this.parametersArray.getReferenceToValuesArray();
    }

    public double compute() {
        return parameters[par] * variables[var];
//        return parametersArray.getValue(par) * variablesArray.getValue(var);
    }

    public double compute(SymbolArray vars) {
        return parameters[par] * vars.getValue(var);
//        return parametersArray.getValue(par)  * vars.getValue(var);
    }

    public ArrayList<Integer> getVariableList() {
        ArrayList<Integer> list = new ArrayList();
        list.add(var);
        return list;
    }
}
